package Controllers

import (
	"context"
	"fmt"
	"work1/DataBase"
	Model "work1/Models"

	"github.com/gin-gonic/gin"
)

type DomainController struct {
	commonController
}

func (that *DomainController) CheckLockStatus(request *gin.Context) {
	type validatorStruct struct {
		DomainId int `form:"domain_id" binding:"required,number"`
	}
	validatos := &validatorStruct{}
	if err := request.ShouldBind(&validatos); err != nil {
		that.SendFailResponse(request, err.Error())
		return
	}
	DomainModel := &Model.Domain{}
	TaskModel := &Model.Task{}
	result := map[string]any{}
	var ctx context.Context
	DataBase.DB.Table(fmt.Sprintf("%v as t1", DomainModel.TableName())).Joins(fmt.Sprintf("inner join %v as t2", TaskModel.TableName())+" on t2.domain_id = t1.id").Where("t2.status >= ? and t1.id = ?", Model.TaskLockIng, request.Request.FormValue("domain_id")).WithContext(ctx).Find(&result)
	if len(result) == 0 {
		that.commonController.SendSuccessResponse(request, result, "")
	} else {
		that.commonController.SendFailResponse(request, "域名锁定中")
	}
}
